#include<bits/stdc++.h>
using namespace std;
int _;
bool solve() {
int n; cin >> n;
vector<vector<int>> a(2, vector<int>(n));
for(auto &p : a) for(int &pp : p) {
char in; cin >> in;
pp=(in<='2' ? 0 : 1);
}
int dir=1, r=0, c=0;
while(r>=0 && c>=0 && r<2 && c<n) {
if(a[r][c]) {
if(dir==0 || dir==2) dir=1, c++;
else dir=2-2*r, r^=1;
} else {
if(dir==1) c++;
else return 0;
}
}
return r && c==n;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> _;
while(_--) cout << (solve() ? "YES\n" : "NO\n");
return 0;
}
Almost correct bracket sequence | Count of integers |
Differences of the permutations | Doctor's Secret |
Back to School | I am Easy |
Teddy and Tweety | Partitioning binary strings |
Special sets | Smallest chosen word |
Going to office | Color the boxes |
Missing numbers | Maximum sum |
13 Reasons Why | Friend's Relationship |
Health of a person | Divisibility |
A. Movement | Numbers in a matrix |
Sequences | Split houses |
Divisible | Three primes |
Coprimes | Cost of balloons |
One String No Trouble | Help Jarvis! |
Lift queries | Goki and his breakup |